<template>
  <base-breadcrumb :title="$route.meta.title">
    <a-row
      :gutter="10"
      class="page-height"
    >
      <!-- 树搜索 -->
      <a-col
        :span="6"
        class="permission-collapsed"
        :class="{ 'permission-tree-collapsed': collapsed }"
      >
        <a-card
          :style="{ border: collapsed ? 'none' : 'border: 1px solid #e8e8e8' }"
          class="page-height-tree"
        >
          <title-name title="组织架构" />
          <PermissionTreeOrganization
            :collapsed.sync="collapsed"
            @select="handleSelect"
          />
        </a-card>
      </a-col>
      <a-col
        :span="18"
        class="permission-collapsed page-height-list-wrapper"
        :style="collapsed ? 'width:calc(100% - 10px)' : ''"
      >
        <searchData
          :search-data="searchArr"
          @search="search"
        />
        <a-card class="page-height-list">
          <div class="table-operator">
            <a-button
              v-btnPermission="'pm_034_add_01'"
              type="primary"
              icon="plus"
              @click="handleUpdate('add', {})"
            >新增会议</a-button>
          </div>
          <list-table
            ref="table"
            size="default"
            rowKey="key"
            :columns="columns"
            :request="loadData"
            :alert="true"
            show-size-changer
            show-quick-jumper
            showPagination="auto"
          >
            <span
              slot="serial"
              slot-scope="text, record, index"
            >{{ index + 1 }}</span>
            <span
              slot="operation"
              slot-scope="text, record"
            >
              <a
                @click="handleUpdate('start', record)"
                v-if="record.status == 20"
                v-btnPermission="'pm_034_edi_02'"
              >查看会议</a>
              <a
                @click="handleUpdate('edit', record)"
                v-if="record.status == 30"
                v-btnPermission="'pm_034_edi_02'"
              >进入会议</a>
              <a
                @click="handleUpdate('look', record)"
                v-if="record.status == 40"
                v-btnPermission="'pm_034_loo_03'"
              >查看会议</a>
            </span>
            <span
              slot="commentedPlan"
              slot-scope="text, record"
            >
              {{ record.meetingExtraVO.commentedPlan }}
            </span>
            <span
              slot="professionComName"
              slot-scope="text, record"
            >
              {{ record.meetingExtraVO.professionComName }}
            </span>
            <span
              slot="avgScore"
              slot-scope="text, record"
            >
              {{ record.meetingExtraVO.avgScore }}
            </span>

            <span
              slot="status"
              slot-scope="text, record"
            >
              <list-status
                :status="record.status"
                conversion="en"
                :text="text"
              ></list-status>
            </span>
          </list-table>
        </a-card>
      </a-col>
    </a-row>
  </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import { STable } from '@/components'
import listStatus from '@/components/list_status/meeting_status'
import { getMeetingList, startMeeting, getSearchList } from '@/api/office/conference'
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'

const columns = [
  {
    title: '序号',
    width: 60,
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '会议名称',
    width: 100,
    dataIndex: 'meetingName'
  },
  {
    title: '会议类型',
    width: 100,
    dataIndex: 'meetingTypeName'
  },
  {
    title: '所属分公司',
    width: 100,
    dataIndex: 'branchComName'
  },
  {
    title: '所属项目',
    width: 100,
    dataIndex: 'projectName'
  },
  {
    title: '召开时间',
    width: 100,
    dataIndex: 'startTime'
  },
  {
    title: '参会人数',
    width: 100,
    dataIndex: 'meetingCount'
  },
  {
    title: '状态',
    width: 100,
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: 170,
    scopedSlots: { customRender: 'operation' }
  }
]
const searchArr = [
  {
    name: '会议名称',
    value: 'meetingName',
    type: 'input'
  },
  {
    name: '召开时间',
    value: 'startEndDate',
    type: 'dateRange'
  }
]
export default {
  name: 'SupervisionMeetingList',
  components: {
    STable,
    listStatus,
    PermissionTreeOrganization
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      // 收缩展开树
      collapsed: false,
      //组织架构选中项
      select: null,
      queryParam: {},
      loadData: async (parameter) => {
        const obj = {}
        // if (!this.select) {
        //   return
        // } 
        // 二级-分公司id
        if (this.select?.tageCode === 'BC') {
          obj.branchComId = this.select.orgId
        }
        // 三级-项目id
        if (this.select?.tageCode === 'PD') {
          obj.projectId = this.select.projectId
        }
        this.queryParam.query = { ...this.queryParam.query, typeId: 8, ...obj }
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        const [err, res] = await getMeetingList(requestParameters)
        return new Promise((resolve, reject) => {
          if (err) {
            reject(err)
          } else {
            resolve(res)
          }
        })
      }
    }
  },
  mounted() {
    // this.getSearchListReq()
  },
  methods: {
    // async getSearchListReq() {
    //     const [err, res] = await getSearchList({ typeId: 8 })
    //     if (!err) {
    //         res.data.forEach((item) => {
    //             item.value = item.id
    //             item.label = item.name
    //         })
    //         searchArr[2].data = res.data || []

    //     }
    //      this.searchArr = searchArr
    // },
    /**
     * @description: 树选中
     * @param {object} node 节点对象
     * @return {void}
     */
    handleSelect(node) {
      this.select = node
      this.search()
    },
    //搜索
    search(val = {}) {
      this.queryParam.query = {
        ...val,
        typeId: 8,
        hsemonth: (val.month && val.month.format('YYYY-MM')) || void 0,
        startTime: (val.startEndDate && val.startEndDate.length && val.startEndDate[0].format('YYYY-MM-DD')) || void 0,
        endTime: (val.startEndDate && val.startEndDate.length && val.startEndDate[1].format('YYYY-MM-DD')) || void 0
      }
      console.log(this.queryParam)

      this.$refs.table.refresh(true)
    },

    // 处理更新操作（新增、编辑）
    async handleUpdate(type, data = {}) {
      if (type == 'del') {
        // const [err, res] = await deleteEquipment({ id: data.id })
        // if (!err) {
        //     this.$message.success('成功')
        //     this.$refs.table.refresh(true)
        // }
      }
      // else if (type == 'start') {
      //     const [err, res] = await startMeeting({ id: data.id })
      //     if (!err) {
      //         this.$message.success('成功')
      //         this.$refs.table.refresh(true)
      //     }
      // }
      else if (type == 'edit' || type == 'look' || type == 'start') {
        this.$router.push({
          name: 'supervisionMeetingInputSummaryNew',
          query: {
            id: data.id || '',
            pageType: type
          }
        })
      } else {
        this.$router.push({
          name: 'supervisionMeetingUpdate',
          query: {
            id: data.id || '',
            pageType: type,
            typeId: 8
          }
        })
      }
    }
  }
}
</script>
